package com.rose.doorto.footbathpay.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.rose.doorto.footbathpay.vo.PayVo;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

//@ConfigurationProperties(prefix = "alipay")
//@Component
//@Data
public class AlipayTemplate {

    //在支付宝创建的应用的id
    private   String app_id = "9021000126614730";

    // 商户私钥，您的PKCS8格式RSA2私钥
    private  String merchant_private_key = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCCq1Um0ftNu+nYquF+qO50aQhOtHZMLn6mZbG2l72MoyjgpOmTDGUpzm8yRFMOAxc4DBo2mRAH2Dwzoasv9So8YxkZIkhEOLE/+EUQHywbMTq8S31kUBxCLqoGLPcfUiaTWklSy1KJKUe6FGClQp3W/ea0VdmN9eNDik6FCT5qk79nc1P5ZlHfJSjZDMNKP7wJ4xpvwlMWSNzLIuCQ6xVfSe5U3edgjdyJ17tJXiVjO8QlSa+O7nqDrEg/vgixfHGLCn87A7a1w/soZb41MNGjbvqgYPHtGWaq4A6IDkJ9bCzc5UKwc8XCAlqGYe5DrVc+bZFV3w1uYKGd+a802AnhAgMBAAECggEADMhL5SdHaRxHzO0yb9yArxyTNnfK1rr5ordyAgWoAjj3x7n6K2tb/hH2qLksUsOUouP0MIEao1nQ0dAv2domzo93JhFHdn0BQdu8jc4u114ie8b6tjRr/0FnWoFNj1/O7D05zQKcyVQjcx2JMsFohV6DEgMP7CYwnCvMcJEt7OjxWM3fZWwRIhsoVlvsr/VKVhYcyE984r0FOOfPCSbSRIaXpktzISoF7FqhD78Gg9NP/X7kBhCtcWi5+fje4RXcRdp5KEBJmIdv/jFS8x/tC3z/I/CDlW+vicaGeYbRe/NHPIJPwYCh1gAwgNeZwO/grlNRS+QXklEDpPVlABYTLQKBgQC3KWkfw3Czd0PE0sj+QEJYRZpLi1Q6wC0rTVccQOjgpl7lYKPANDbUw0DwTWHyY26lvvAhLgHQijyxXfMeOLAKuqoNCyF95TI/Q5qaxjm9gXFyXHD6jLtz85OeEOw3XbVZF42beQn/SLWyA33RpaDPoK1WsX/uOdCTBsYFFDbsBwKBgQC2ofqz3A4xvuEX70D4/pIApFx/5CPGY16ABPZgPwDpUWvtKpHdg+dCTND00UFPW0A/jO2kECe9+fz4kPAO2eHKX9ICq3QY6rkV37WmT4ETHjH6HL0SpsuPjEo7rIyo5ua8x2WeW+9VCyC2r4e6C5hsscGug7tsvFiN0CRzzTWw1wKBgEN9wdvPc3bd6p3bIe72FLxcIWfW1lmzuLEtFX02udkV1P/mpVBMrSunKwWhLgdX9kyi1+8R+d8zIPwmZ1BqiQvbDpAx2sx+KQ7AxXZktqAK05fVUlgwhV5Lkch76d7Y69sBX8+7QSDNVQ5cVP9sbZ40UcsRKtfIe//BTjRO55H/AoGATv38a3LQiN+giDOpjIi/KZvtjjtk5dfw9bovvi1B/aiD3867zG3SxrBm6JzhfKthPJt95ao/JkJMEk7OJf5DVL7hHNp/mo9bgoSCEu7sSxKSVzW66ahO/0WUjf7xz9QfFKPB5h6pg8UOXzXIpMWDJfA0b4D2ve8w9hWCzruBb30CgYBoPDr0CiASs7NZ4OT/fWzCcudLuHoZDlvGQKFUmQgsiymum0a8bKtMbs3uLl+uwy+gRdSvFf7Juo1fZlnSE46nGQfzet0A03ICa/gtebH6gMpotsvOx5ZsSojDVE9kF6caKBsieKoQHyq37hAWr2GaXHWOJKXl/Dd4SL+7jeqQFg==";
    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    private  String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgqtVJtH7Tbvp2KrhfqjudGkITrR2TC5+pmWxtpe9jKMo4KTpkwxlKc5vMkRTDgMXOAwaNpkQB9g8M6GrL/UqPGMZGSJIRDixP/hFEB8sGzE6vEt9ZFAcQi6qBiz3H1Imk1pJUstSiSlHuhRgpUKd1v3mtFXZjfXjQ4pOhQk+apO/Z3NT+WZR3yUo2QzDSj+8CeMab8JTFkjcyyLgkOsVX0nuVN3nYI3cide7SV4lYzvEJUmvju56g6xIP74IsXxxiwp/OwO2tcP7KGW+NTDRo276oGDx7RlmquAOiA5CfWws3OVCsHPFwgJahmHuQ61XPm2RVd8NbmChnfmvNNgJ4QIDAQAB";
    // 服务器[异步通知]页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    // 支付宝会悄悄的给我们发送一个请求，告诉我们支付成功的信息
    private  String notify_url;

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    //同步通知，支付成功，一般跳转到成功页
    private  String return_url;

    // 签名方式
    private  String sign_type = "RSA2";

    // 字符编码格式
    private  String charset = "utf-8";

    // 支付宝网关； https://openapi.alipaydev.com/gateway.do
    private  String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

//    public  String pay(PayVo vo) throws AlipayApiException {
//
//        //AlipayClient alipayClient = new DefaultAlipayClient(AlipayTemplate.gatewayUrl, AlipayTemplate.app_id, AlipayTemplate.merchant_private_key, "json", AlipayTemplate.charset, AlipayTemplate.alipay_public_key, AlipayTemplate.sign_type);
//        //1、根据支付宝的配置生成一个支付客户端
//        AlipayClient alipayClient = new DefaultAlipayClient(gatewayUrl,
//                app_id, merchant_private_key, "json",
//                charset, alipay_public_key, sign_type);
//
//        //2、创建一个支付请求 //设置请求参数
//        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
//        alipayRequest.setReturnUrl(return_url);
//        alipayRequest.setNotifyUrl(notify_url);
//
//        //商户订单号，商户网站订单系统中唯一订单号，必填
//        String orderSn = vo.getOrderSn();
//        //付款金额，必填
//        String total_amount = vo.getAggregate();
//        //订单名称，必填
//        String subject = vo.getProjectName();
//        //商品描述，可空
//        String body = vo.getBody();
//
//        alipayRequest.setBizContent("{\"orderSn\":\""+ orderSn +"\","
//                + "\"total_amount\":\""+ total_amount +"\","
//                + "\"subject\":\""+ subject +"\","
//                + "\"body\":\""+ body +"\","
//                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
//
//        String result = alipayClient.pageExecute(alipayRequest).getBody();
//
//        //会收到支付宝的响应，响应的是一个页面，只要浏览器显示这个页面，就会自动来到支付宝的收银台页面
//        System.out.println("支付宝的响应："+result);
//
//        return result;
//
//    }
}
